package me.snowiest.snowdrift.controller;

import me.snowiest.snowdrift.entity.User;
import me.snowiest.snowdrift.service.PermissionService;
import me.snowiest.snowdrift.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @PostMapping("token")
    public CommonResult login(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            @RequestParam(value = "verifyCode", required = false) String verifyCode
    ) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        String token = permissionService.getToken(user);
        return CommonResult.success().data("token", token);
    }

}
